Description of CTabView Written by Gerry High 74750,2456 CIS Revision History Version Date 1.2 4/13/94 Added Vertical tabs (left, right). Some work was done by Douglas Brown Allow runtime setting of tab margins, height, style. Modified ALT+mnemonic view switching to not require accelerator definitions. Changed "toupper" to "AnsiUpper". Changed hardcoded RGB values to use GetSysColor. Fixed bug with OnMouseActivate. Version Date 1.1 3/16/94 Removed extra frame in each view. Added code for ALT+Mnemonic view switching. Added suggestions from various people in the forum. Added MS Word 6.0 look to tabs (compliments of David Hollifield). Version Date 1.0 2/15/94 Initial posting Description This is a sample application using the CTabView class. Expand the zip file using the -d option and use VC++ to build the project. The project uses the DLL version of MFC (mfc250d.dll) which should be in your windows\system directory. To use the CTabView class in your own projects do the following: 1. Subclass CTabView with the class you wish to manage your tabs (e.g. CMainView : public CTabView ... You should provide an "OnInitialUpdate" member method. 2. Add tabview.cpp and your subclass of CTabView to your project. 3. Modify the application class to use your view class. Modify the include file name to be your view.h. Modify your document template to specify the new view (e.g.) AddDocTemplate(new CMultiDocTemplate(IDR_TABTYPE, RUNTIME_CLASS(CTabDoc), RUNTIME_CLASS(CMDIChildWnd), // standard MDI child frame RUNTIME_CLASS(CMainView))); // your view goes here 4. In your OnInitialUpdate method add your views to the CTabView class using the method "addTabView" addTabView(RUNTIME_CLASS(COrderView),GetDocument(),"&Options",this,); addTabView(RUNTIME_CLASS(CDrawView),GetDocument(),"&Graphics",this, TRUE,FALSE); Finally, call the CTabView "OnInitialUpdate" method from your OnInitialUpdate method. CTabView::OnInitialUpdate(); An example from mainview.cpp is shown below: void CMainView::OnInitialUpdate() { COrderView* pOrderView = (COrderView*) addTabView(RUNTIME_CLASS(COrderView),GetDocument(), "&Options"); ASSERT(pOrderView != NULL); pOrderView->m_pTabView = this; CDrawView* pDrawView = (CDrawView*) addTabView(RUNTIME_CLASS(CDrawView),GetDocument(), "&Graphics",TRUE,FALSE); ASSERT(pDrawView != NULL); pDrawView->m_pTabView = this; CEditVw* pEditView = (CEditVw*) addTabView(RUNTIME_CLASS(CEditVw),GetDocument(), "&Edit",TRUE,FALSE); ASSERT(pEditView != NULL); pEditView->m_pTabView = this; CTabView:OnInitialUpdate(); } This example creates three tabs (Options, Graphics, and Edit). The last thing done in the OnInitialUpdate method is to call the base class OnInitialUpdate method. 5. If you override the OnDraw method of CTabView you must call the CTabView::OnDraw method as well. 6. If you override the OnSize method of CTabView you must call the CTabView::OnSize method as well. Known Problems/Limitations 1. A disabled tab currently uses the system color COLOR_GRAYTEXT; this may not yield a color that will work for all color schemes and result in the text being invisible. In the future I will fix this to use the GrayString function. 2. The Chicago look is only implemented for the TABSONTOP orientation. 3. For vertical orientations the underline is not drawn for the tab mnemonic. The reason for this is that TextOut doesn't support automatic underlining. Disclaimer, etc. Any questions, problems, suggestions, etc. should be directed to the author Gerry High 74750,2456 CIS. Feel free to use this in your own programs. This class is freeware and is provided as is. In the near future I may update this class to support multi-row tabs and dialog support. Other possibilities include tear-off tabs and owner draw tabs. Class Reference class CTabView : public CView ______________________________________________________________ CTabView::addTabView virtual CView* addTabView(CRuntimeClass* pViewClass, CDocument* pDoc, char* tabLabel, BOOL border = FALSE, BOOL show = TRUE, int tabWidth = 100); pViewClass Pointer to CRuntimeClass of child view. pDoc Pointer to document. pTabLabel Pointer to the string for the tab label. border Requests whether a border is to be drawn around the view. show Requests whether to view is to be shown. tabWidth Specifies the width of the tab in pixels. Remarks Call this function to add a tab. ______________________________________________________________ CTabView::doSysCommand void doSysCommand(UINT nID, long lParam); Remarks Call this function from an OnSysCommand handler to pass "ALT-mnemonic" keys through from the child view for view switching. Example void CDrawView::OnSysCommand(UINT nID, long lParam) { if(m_pTabView->doSysCommand(nChar,lParam)) return; CScrollView::OnSysCommand(nChar,lParam); } ______________________________________________________________ CTabView::enableView void enableView(int index, BOOL bEnable = TRUE); index Specifies the zero based index of the tab to be enable or disabled. bEnable Specifies whether the given tab is to be enabled or disabled. Remarks Call this function to enable or disable a tab. Example enableView(1, FALSE); //disable tab 1 ______________________________________________________________ CTabView::setFrameBorderOn void setFrameBorderOn(BOOL bOn = TRUE); bOn Specifies whether the frame border is to be drawn. Remarks Call this function to turn on or off the tab frame. ______________________________________________________________ CTabView::setLAF void setLAF(eLookAndFeel LAF); LAF Is a enum of type eLookAndFeel. Must be either LAF_MSWORD or LAF_CHICAGO. Remarks Call this function to set the look and feel to either Chicago or MS Word. ______________________________________________________________ CTabView::setMargin void setMargin(int margin); margin The margin width in pixels. Remarks Call this function to set the margin around the tab frame. ______________________________________________________________ CTabView::setTabHeight void setTabHeight(int height); height The tab height in pixels. Remarks Call this function to set the height of the tabs. ______________________________________________________________ CTabView::setTabPosition void setTabPosition(eTabPosition tabPosition); tabPosition Specifies the position of the tabs. Must be one of TABSONTOP, TABSONLEFT, TABSONLEFTBOT, TABSONRIGHT, TABSONRIGHTBOT, or TABSONBOTTOM. Remarks Call this function to set the postiton of the tabs. ______________________________________________________________ CTabView::switchTab void switchTab(int viewIndex); viewIndex Specifies the zero-based index of the tab to be switched to. Remarks Call this function to switch between different tabs.